#!/usr/bin/env python3
"""
使用tkinter创建内核管理工具图标
"""
import tkinter as tk
from PIL import Image, ImageDraw
import os

# 创建tkinter根窗口（隐藏）
root = tk.Tk()
root.withdraw()

# 创建Canvas
canvas = tk.Canvas(root, width=48, height=48, bg='#4A90E2', highlightthickness=0)
canvas.pack()

# 绘制黑色圆圈
canvas.create_oval(4, 4, 44, 44, outline='#000000', width=3)

# 绘制红色的字母"K"
# 使用线条绘制一个填充圆圈内部的红色K
# K的垂直线
canvas.create_line(20, 8, 20, 40, fill='#FF0000', width=5)
# K的斜线
canvas.create_line(20, 24, 36, 8, fill='#FF0000', width=5)
canvas.create_line(20, 24, 36, 40, fill='#FF0000', width=5)

# 导出为PostScript格式
canvas.update()
canvas.postscript(file="kernel-management.eps")

# 关闭tkinter窗口
root.destroy()

# 将EPS转换为PNG
try:
    from PIL import Image
    # 打开EPS文件并转换为PNG
    img = Image.open("kernel-management.eps")
    img.save("kernel-management.png", "PNG")
    # 删除临时EPS文件
    os.remove("kernel-management.eps")
    print("图标已创建为 kernel-management.png")
    print("请将其保存为 debian/usr/share/icons/hicolor/48x48/apps/kernel-management.png")
except Exception as e:
    print(f"无法自动转换为PNG格式: {e}")
    print("图标草图已创建为 kernel-management.eps")
    print("请将其转换为PNG格式并保存为 debian/usr/share/icons/hicolor/48x48/apps/kernel-management.png")